package org.luxor.commons.storage.config;

import org.luxor.commons.storage.client.aliyun.AliyunProperties;
import org.luxor.commons.storage.client.aliyun.AliyunStorageClient;
import org.luxor.commons.storage.client.disk.DiskProperties;
import org.luxor.commons.storage.client.disk.DiskStorageClient;
import org.luxor.commons.storage.client.fastdfs.FastDfsProperties;
import org.luxor.commons.storage.client.fastdfs.FastDfsStorageClient;
import org.luxor.commons.storage.client.minio.MinioProperties;
import org.luxor.commons.storage.client.minio.MinioStorageClient;
import org.luxor.commons.storage.client.qcloud.QcloudProperties;
import org.luxor.commons.storage.client.qcloud.QcloudStorageClient;
import org.luxor.commons.storage.client.qiniu.QiniuProperties;
import org.luxor.commons.storage.client.qiniu.QiniuStorageClient;
import org.luxor.commons.storage.service.IFileStorageService;
import org.luxor.commons.storage.service.IThumbImageService;
import org.luxor.commons.storage.service.impl.FileStorageServiceImpl;
import org.luxor.commons.storage.service.impl.ThumbImageServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * FileStorage 全局配置
 *
 * @author Mr.Yan  @date 2019/11/29
 */
@Configuration
@EnableConfigurationProperties({DiskProperties.class, MinioProperties.class, FastDfsProperties.class, QiniuProperties.class, AliyunProperties.class, QcloudProperties.class})
public class FileStorageAutoConfig {

    @Bean
    @ConditionalOnMissingBean
    public DiskStorageClient diskStorageClient(DiskProperties diskProperties) {
        return new DiskStorageClient(diskProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public MinioStorageClient minioStorageClient(MinioProperties minioProperties) {
        return new MinioStorageClient(minioProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public FastDfsStorageClient fastDfsStorageClient(FastDfsProperties fastDfsProperties) {
        return new FastDfsStorageClient(fastDfsProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public QiniuStorageClient qiniuStorageClient(QiniuProperties qiniuProperties) {
        return new QiniuStorageClient(qiniuProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public AliyunStorageClient aliyunStorageClient(AliyunProperties aliyunProperties) {
        return new AliyunStorageClient(aliyunProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public QcloudStorageClient qcloudStorageClient(QcloudProperties qcloudProperties) {
        return new QcloudStorageClient(qcloudProperties);
    }

    @Bean
    public IFileStorageService fileStorageService() {
        return new FileStorageServiceImpl();
    }

    @Bean
    public IThumbImageService thumbImageService() {
        return new ThumbImageServiceImpl();
    }
}
